home *** CD-ROM | disk | FTP | other *** search
/ Magnum One / Magnum One (Mid-American Digital) (Disc Manufacturing).iso / d12 / ecstr3.arc / STRXNCAT.C < prev    next >
C/C++ Source or Header  |  1987-03-04  |  2KB  |  51 lines

  1. /*  File   : strxncat.c
  2.     Author : Richard A. O'Keefe.
  3.     Updated: 2 June 1984
  4.     Defines: strxncat()
  5.  
  6.     strxncat(dst, len, src1, ..., srcn, NullS)
  7.     moves the first len bytes of the concatenation of dst,src1,...,srcn
  8.     to dst, terminating it with a NUL character unless len runs out, and
  9.     returns the original value of dst.
  10.     It is just like strcat except that it concatenates multiple sources.
  11.     Roughly, strxncat(d, L, s1, ..., sn) <=> strxncpy(d, L, d, s1, ..., sn).
  12.     Beware: the last argument should be the null character pointer.
  13.     Take VERY great care not to omit it!  Also be careful to use NullS
  14.     and NOT to use 0, as on some machines 0 is not the same size as a
  15.     character pointer, or not the same bit pattern as NullS.
  16.  
  17.     Note: strxncat is like strncat in that it will add at most one NUL,
  18.     and may in consequence move fewer than len characters.  No so the
  19.     strxncpy and strxnmov routines, which resemble strncpy and strnmov.
  20. */
  21.  
  22. #include "strings.h"
  23. #include <varargs.h>
  24.  
  25. /*VARARGS*/
  26. char *strxncat(va_alist)
  27.     va_dcl
  28.     {
  29.      va_list pvar;
  30.        register char *dst, *src;
  31.        register int len;
  32.        char *bogus;
  33.  
  34.        va_start(pvar);
  35.        dst = va_arg(pvar, char *);
  36.        bogus = dst;
  37.        len = va_arg(pvar, int);
  38.        while (*dst)
  39.            if (--len < 0) return bogus;
  40.            else dst++;
  41.        src = va_arg(pvar, char *);
  42.        while (src != NullS) {
  43.            do if (--len < 0) return bogus;
  44.            while (*dst++ = *src++);
  45.            dst--;
  46.            src = va_arg(pvar, char *);
  47.        }
  48.        return bogus;
  49.     }
  50.  
  51.